﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TankGameV1._0
{
    abstract class GameObject
    {
        //用枚举类型来代表坦克移动的方向
        public enum Direction
        {
            Up,Down,Left,Right
        }
        #region 坦克的属性有移动速度，生命值，位置坐标，高度，宽度,移动方向
        public int X
        {
            get;
            set;
        }
        public int Y
        {
            get;
            set;
        }
        public int Height
        {
            get;
            set;
        }
        public int Width
        {
            get;
            set;
        }
        public int Speed
        {
            get;
            set;
        }
        public int Life
        {
            get;
            set;
        }
        public Direction Dir
        {
            get;
            set;
        }
        #endregion
        //该类的构造函数
        public GameObject(int x,int y,int speed,int width,int heigth,int life,Direction dir)
        {
            this.X = x;
            this.Y = y;
            this.Speed = speed;
            this.Height = heigth;
            this.Width = width;
            this.Life = life;
            this.Dir = dir;
        }
        public GameObject(int x,int y) : this(x, y, 0, 0, 0, 0, 0)
        {

        }
        public GameObject(int x,int y,int width,int heigth) : this(x, y, 0, width, heigth, 0, 0)
        {

        }
        //要有一个抽象的绘制游戏对象的Draw()方法（每一个坦克对象都要不停绘自己的位置）
        public abstract void Draw(Graphics g);
        //有一个坦克移动的Move方法(虚方法代表子类可以重写也可以不重写该方法)
        public virtual void Move()
        {
            switch (this.Dir)
            {   //如果坦克向上移动其纵坐标要减小,且减小的是其速度大小
                case Direction.Up:
                    this.Y -= this.Speed;
                    break;
                case Direction.Down:
                    this.Y += this.Speed;
                    break;
                case Direction.Left:
                    this.X -= this.Speed;
                    break;
                case Direction.Right:
                    this.X += this.Speed;
                    break;
            }
            //要判断坦克是否出界
            if (this.X <= 0)
            {
                this.X = 0;
            }
            if (this.Y <= 0)
            {
                this.Y = 0;
            }
            if (this.X >= 720)
            {
                this.X = 720;
            }
            if (this.Y >= 600)
            {
                this.Y = 600;
            }
        }
        //有一个返回矩形的getRectangle方法,检测坦克碰撞
        public Rectangle GetRectangle()
        {
            return new Rectangle(this.X, this.Y, this.Width, this.Height);
        }
    }
}
